package jess;

// Executes both rules and actions

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import utils.CassandraJMXProxy;
import utils.RingUtils;
import cassandra.Action;
import cassandra.Emailer;
import cassandra.Ring;

import org.apache.cassandra.dht.Range;
import org.apache.cassandra.dht.Token;

import exception.RuleBasedMonitoringException;

public class Demo {
	static  int cnodesUp=0,cnodesDown=0,cjoinnodes=0; 

	public static void main(String[] args) {
		try {
	
			JessRuleEngine engine = new JessRuleEngine();
			
				CassandraJMXProxy monitor = new CassandraJMXProxy();
			Ring ring = monitor.getRingImage();
			//RingUtils ringChk = new RingUtils(ring);
			
			System.out.println("*****  Nodes Up ****");

			for(String key: ring.getUpNodes())  {
				System.out.println(key);
			     cnodesUp++;
			}
			
			System.out.println("*****  Nodes Down ****");
			for(String key: ring.getDownNodes())  {
				System.out.println(key);
			     //cnodesUp++;
			}
			
			 System.out.println("cantidad de nodos UP "+cnodesUp);	
		    
			
			System.out.println("*****  Node's Token ****");
			
		Map<Token, String> tokens = ring.getTokenNodes();
		
				System.out.println(tokens.keySet().size());
			
	            
	
			
			
			
			Iterator<Action> operations = engine.run();
			System.out.println("Operations");
			while (operations.hasNext()) {
				operations.next().call();
			}
			
		} catch (JessException e) {
			e.printStackTrace();
		} catch (RuleBasedMonitoringException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 

	}

}
